home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17678 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: kbad.eglin.af.mil!rpi!not-for-mail
  2. From: Matt Young <youngm@interramp.com>
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Re: Help with IOStreams needed!
  5. Date: 16 Apr 1996 20:10:40 -0000
  6. Organization: PSI Public Usenet Link
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: Dietmar.Kuehl@uni-konstanz.de
  9. Message-ID: <4l0us0$spi@netlab.cs.rpi.edu>
  10. References: <4kupd8$khj@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: Tue, 16 Apr 1996 11:29:10 -0700
  13.  
  14. Victor Muslin wrote:
  15. > I am new to IOStreams, so please pardon if this is a silly question...
  16. > I open a file as an ofstream. When I write to it I would like to lock it to
  17. > ensure that no other process can write until I am done. In C I could've used
  18. > an flock() to which I would pass a file descriptor obtained from open(). How
  19. > do I do I find the file descriptor associated with an ofstream (or ostream for
  20. > that matter)? Or, is there a better way to lock an output stream in C++?
  21. > If you could copy your reply to vmuslin@prodigy.com I would appreciate it.
  22. >    {Those who post questions to a newsgroup are expected to read the
  23. >    newsgroup for the reply.  See the netnews netiquette guide. -mod}
  24. > Thanks.
  25. >       [ Articles to moderate: mailto:c#include <fstream.h>
  26.  
  27.  
  28. ++-submit@netlab.cs.rpi.edu ]
  29. >       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  30. >       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  31. >       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  32.  
  33.  
  34. You can get the file descriptor from you ofstream this way:
  35.  
  36.  
  37.     ofstream ofs("junk.txt");
  38.  
  39.     int fd = ofs.rdbuf()->fd();
  40.  
  41.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  42.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  43.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  44.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  45.